package sing.rabbit.direct.consumer.consume;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
//import sing.rabbit.direct.common.Message;

import static sing.rabbit.direct.common.DirectConfigurations.*;

/**
 * 使用 @RabbitListener + @RabbitHandler 方式 <br>
 *
 * 且 @RabbitListener 使用 bindings 参数指定监听队列
 *
 * @author xing
 * @date 2022/9/8 7:58
 */
@Profile("sample_1")
@Component
@RabbitListener(bindings = {@QueueBinding(
        value = @Queue(name = DIRECT_QUEUE_NAME_1),
        exchange = @Exchange(name = DIRECT_EXCHANGE_NAME),
        key = {DIRECT_ROUTING_KEY_DEV}
)})
public class DirectQueueListener {

    /**
     * 这里使用了重写的 Message, 保证 Provider 发送消息为 Message 时可以正常打印出 Body
     */
    @RabbitHandler(isDefault = true)
    public void consumeByDev(Message message) {
        System.out.println("get message: " + message);
    }

}
